package cn.iocoder.yudao.module.strategyPlanUser.controller.admin.strategyPlanUser;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.strategyPlanUser.controller.admin.strategyPlanUser.vo.*;
import cn.iocoder.yudao.module.strategyPlanUser.dal.dataobject.strategyPlanUser.StrategyPlanUserDO;
import cn.iocoder.yudao.module.strategyPlanUser.convert.strategyPlanUser.StrategyPlanUserConvert;
import cn.iocoder.yudao.module.strategyPlanUser.service.strategyPlanUser.StrategyPlanUserService;

@Tag(name = "管理后台 - 企业战略-计划-人力落地表（短期、长期）")
@RestController
@RequestMapping("/strategyPlanUser/")
@Validated
public class StrategyPlanUserController {

    @Resource
    private StrategyPlanUserService strategyPlanUserService;

    @PostMapping("/create")
    @Operation(summary = "创建企业战略-计划-人力落地表（短期、长期）")
    @PreAuthorize("@ss.hasPermission('strategyPlanUser:create')")
    public CommonResult<Long> create(@Valid @RequestBody StrategyPlanUserCreateReqVO createReqVO) {
        return success(strategyPlanUserService.create(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新企业战略-计划-人力落地表（短期、长期）")
    @PreAuthorize("@ss.hasPermission('strategyPlanUser:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody StrategyPlanUserUpdateReqVO updateReqVO) {
        strategyPlanUserService.update(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除企业战略-计划-人力落地表（短期、长期）")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('strategyPlanUser:delete')")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        strategyPlanUserService.delete(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业战略-计划-人力落地表（短期、长期）")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('strategyPlanUser:query')")
    public CommonResult<StrategyPlanUserRespVO> get(@RequestParam("id") Long id) {
        StrategyPlanUserRespVO strategyPlanUserRespVO = strategyPlanUserService.getStrategyPlanUserRespVO(id);
        return success(strategyPlanUserRespVO);
    }

    @GetMapping("/list")
    @Operation(summary = "获得企业战略-计划-人力落地表（短期、长期）列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('strategyPlanUser:query')")
    public CommonResult<List<StrategyPlanUserRespVO>> getList(@RequestParam("ids") Collection<Long> ids) {
        List<StrategyPlanUserDO> list = strategyPlanUserService.getList(ids);
        return success(StrategyPlanUserConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得企业战略-计划-人力落地表（短期、长期）分页")
    @PreAuthorize("@ss.hasPermission('strategyPlanUser:query')")
    public CommonResult<PageResult<StrategyPlanUserRespVO>> getPage(@Valid StrategyPlanUserPageReqVO pageVO) {
        PageResult<StrategyPlanUserRespVO> strategyPlanUserRespVOPageResult = strategyPlanUserService.getPageStrategyPlanUserRespVO(pageVO);

        return success(strategyPlanUserRespVOPageResult);
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出企业战略-计划-人力落地表（短期、长期） Excel")
    @PreAuthorize("@ss.hasPermission('strategyPlanUser:export')")
    @OperateLog(type = EXPORT)
    public void exportExcel(@Valid StrategyPlanUserExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<StrategyPlanUserDO> list = strategyPlanUserService.getList(exportReqVO);
        // 导出 Excel
        List<StrategyPlanUserExcelVO> datas = StrategyPlanUserConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "企业战略-计划-人力落地表（短期、长期）.xls", "数据", StrategyPlanUserExcelVO.class, datas);
    }

}
